package com.cxh.rmsq.ui.activity

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.cxh.rmsq.R
import com.cxh.rmsq.ui.BaseActivity
import com.cxh.rmsq.ui.activity.self.BindPhoneActivity
import com.cxh.rmsq.ui.activity.self.SuggestActivity

/**
 * 未收到验证码页面
 */
class NoVerificationCodeActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_no_verification_code)
        findViewById<LinearLayout>(R.id.iv_back).setOnClickListener {
            finish()
        }
        initData()
    }

    fun initData() {
        var str = "如果您无法收到验证码，建议您:\n" +
                "1、请检查您的手机号是否输入正确，是否是空号;\n" +
                "2、请检查您的手机号是已经停机/关机/没有信号;\n" +
                "3、请检查您的垃圾短信箱，确保短信没有被屏蔽;\n" +
                "4、若您的原注册手机号因停机/丢失等原因已不再使用，无法获取验证码，可点击进行"
        var str2 = "，更换绑定手机号;\n" +
                "5、若您当日验证码获取次数已达上限，请您于24小时后再次获取，同时建议您可以使用密码登录(若忘记密码，可在登录页面点击登录遇到问题-找回密码进行修改);\n" +
                "6、如尝试以上方法后仍无法收到，请提供您的手机号，进行"
        val ssb = SpannableStringBuilder()
        ssb.append(str)
        ssb.append(
            "自助换绑",
            ForegroundColorSpan(Color.parseColor("#FF8400")),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        ssb.append(str2)
        ssb.append(
            "意见反馈",
            ForegroundColorSpan(Color.parseColor("#FF8400")),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        ssb.append("。")
        var registrationTerms = findViewById<TextView>(R.id.textview)

        val clickableSpanOne: ClickableSpan = object : ClickableSpan() {
            override fun onClick(view: View) {
                startActivity(Intent(this@NoVerificationCodeActivity, BindPhoneActivity::class.java))
            }

            override fun updateDrawState(ds: TextPaint) {
                super.updateDrawState(ds)
                ds.color = Color.parseColor("#FF8400")
                // 设置下划线 true显示、false不显示
                //paint.setTypeface(Typeface.DEFAULT_BOLD);
                ds.isUnderlineText = false
            }
        }

        val clickableSpanTwo: ClickableSpan = object : ClickableSpan() {
            override fun onClick(view: View) {
                startActivity(Intent(this@NoVerificationCodeActivity, SuggestActivity::class.java))
            }

            override fun updateDrawState(ds: TextPaint) {
                super.updateDrawState(ds)
                ds.color = Color.parseColor("#FF8400")
                // 设置下划线 true显示、false不显示
                //paint.setTypeface(Typeface.DEFAULT_BOLD);
                ds.isUnderlineText = false
            }
        }

        ssb.setSpan(clickableSpanOne, str.length, str.length + 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        ssb.setSpan(clickableSpanTwo, ssb.length - 4, ssb.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)

        registrationTerms.setText(ssb)
        registrationTerms.setMovementMethod(LinkMovementMethod.getInstance()) // 不设置 没有点击事件

        registrationTerms.setHighlightColor(Color.TRANSPARENT) // 设置点击后的颜色为透明

    }
}